from langchain_core.tools import tool
from langchain_core.messages import AIMessage
from langgraph.prebuilt import ToolNode

@tool
def get_weather(location:str):
    """用户接收当前城市"""
    if location.lower() in ['sf','san francisco']:
        return "It's 16 degress and foggy"
    else:
        return "It's not 32 degress"

@tool
def get_coolest_cities():
    """获取最冷城市名称"""
    return "哈尔滨"

message_with_multiple_tool_calls = AIMessage(
    content="",
    tool_calls=[
        {
            "name": "get_weather",
            "args": {"location": "sf"},
            "id": "4343",
            "type": "tool_call"
        },
        {
            "name": "get_coolest_cities",
            "args": {},
            "id": "43431",
            "type": "tool_call"
        }
    ]
)
tools = [get_weather,get_coolest_cities]
tool_node = ToolNode(tools)

tool_node_output = tool_node.invoke({"messages":[message_with_multiple_tool_calls]})
print(tool_node_output)